I have two files.
In import I do:
const export = require('export')
This will successful import the module from export.js. When I do require('export.js') (with file ending) it is also working.
So I was wondering what is the difference there? Is without slower?
Node.js automatically resolves some extensions. For example: .js, .json, etc. No, it works the same with or without the extension.
The difference between import/export and require is that require uses commonjs under the hood. While the import was introduced in ES6.
Even if you use ES6 import it's still transpiled into thecommonjs. But using ES6 is recommended because with the time, it will be widely supported.
Performance-wise the difference will be negligible because the module files are evaluated only once but you will have to benchmark it, if you are very keen on the performance.